package com.ikas.ai.server.module.instance.controller;

import com.ikas.ai.handle.JsonResult;
import com.ikas.ai.server.aop.Pageable;
import com.ikas.ai.server.module.AbstractBean;
import com.ikas.ai.server.module.instance.model.DorisWorkFlowInstance;
import com.ikas.ai.server.module.instance.model.dto.WorkFlowBatchQuery;
import com.ikas.ai.server.module.instance.service.DorisWorkFlowInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @menu 工况实例相关接口
 *
 * @Author: qi.yilai
 * @Date: 2023/4/25 10:34
 * @Version: 1.0.0
 **/
@RestController
@RequestMapping("/work/instance")
public class WorkInstanceFlowController extends AbstractBean {

    @Autowired
    private DorisWorkFlowInstanceService dorisWorkFlowInstanceService;

    /**
     * 根据名称获取工况批次数据
     *
     * @param machineNo 例如TU01
     * @param wcName    例如TB26
     * @return
     */
    @Pageable(sortBy = DorisWorkFlowInstance.Fields.createTime, sortType = "desc")
    @GetMapping("/findFlowInstance/{machine_no}/{wc_name}")
    public JsonResult findWOrkConditionFlow(@PathVariable("machine_no") String machineNo, @PathVariable("wc_name") String wcName) {
        return JsonResult.ok(dorisWorkFlowInstanceService.findWorkFlowInstance(machineNo, wcName));
    }

    /**
     * 获取工况流程批次下拉列表
     *
     * @param query 工况流程批次查询
     * @return
     */
    @PostMapping("/selectBatchList")
    public JsonResult selectBatchList(@RequestBody WorkFlowBatchQuery query) {
        return JsonResult.ok(dorisWorkFlowInstanceService.selectBatchList(query));
    }

    /**
     * 根据工况实例id获取工况实例详情
     *
     * @return
     */
    @GetMapping("/findFlowInstance/detail/{id}")
    public JsonResult findWOrkConditionFlow(@PathVariable(value = "id", required = true) Long id) {
        return JsonResult.ok(dorisWorkFlowInstanceService.detail(id));
    }

}
